
  var alarmIndex = null;
  var newAlarmArr = [];
  $(function () {
  // 报警列表滚动条
  $(".newAlarmListBox_scroll").yi_scroll();
  newAlarmFn();

  // 点击报警列表处理按钮，弹出报警框
  $('#newAlarm').on('click', '.handleBtn', function () {
    event.preventDefault();
    alarmIndex = $(this).attr('index');
    $('#newAlarmModal select').val('误报');
    $("#newAlarmModalBox").addClass("is-visible3");
    var arr = newAlarmArr[alarmIndex];
    console.log(arr);
    var linkMan1 = arr.linkMain1 ? arr.linkMain1 + '/' + arr.linkPhone1 : '';
    var linkMan2 = arr.linkMain2 ? arr.linkMain2 + '/' + arr.linkPhone2 : '';
    var linkMan3 = arr.linkMain3 ? arr.linkMain3 + '/' + arr.linkPhone3 : '';
    $('#newAlarmModal .devCode').text(arr.devCode);
    $('#newAlarmModal .alarmType').text(arr.alarmName);
    $('#newAlarmModal .alarmTime').text(moment(arr.beginTime).format('YYYY-MM-DD HH:mm:ss'));
    $('#newAlarmModal .linkMan1').text(linkMan1);
    $('#newAlarmModal .linkMan2').text(linkMan2);
    $('#newAlarmModal .linkMan3').text(linkMan3);
    $('#newAlarmModal .address span').text(arr.address);
    console.log(alarmIndex)
    $("#newAlarmModal .coordinationBtn").attr('index',alarmIndex);
    // // 如果报警类型是 终端报警 则显示 交互 按钮
    // if(arr.alarmName=='交互终端'){
    //   $('#newAlarmModalBox ')
    // }
  });
  //  关闭窗口
  $("#newAlarmModalBox").on("click", function (event) {
    if (
      $(event.target).is(".cd-popup-close")
    ) {
      event.preventDefault();
      $(this).removeClass("is-visible3");
    }
  });
  //   0: "c4cd8232e6e2edd7"
  // 1: "梵天寺路55号二楼过道2"
  // 2: "街道"
  // 3: "烟雾报警"
  // 4: "南星街道"
  // 5: "2018-11-04T23:06:06.000+0000"
  // 6: 119283
  // 7: "30.224156"
  // 8: "120.173955"
  // 9: "叶国惠"
  // 10: "社区消防"
  // 11: "社区消防"
  // 12: "13958169198"
  // 13: "86554119"
  // 14: "86554119"
  // 点击报警框处理按钮，处理此条报警
  $('#newAlarmModalBox').on('click', '.btnClick', function () {
    var arr = newAlarmArr[alarmIndex];
    var alarmId = arr.alarmId;
    var disposeStatus = $(this).attr('disposeStatus');
    var devCode = arr.devCode;
    var remark = $('#newAlarmModalBox .remarkText').val();
    var alarmReasons = $('#newAlarmModalBox .alarmReason select').val();
    handleIgnoreAjax(alarmId, disposeStatus, devCode, remark, alarmReasons);
  });

});

// 获取报警列表
function newAlarmFn() {
  $.ajax({
    url: '/alarm/notdispose',
    success: function (res) {
      console.log(res);
      if (res.status == 200) {
        var data = res.data;
        newAlarmArr = data;
        $('#newAlarm .newAlarmListBox ._panel-box').html('');
        if (data.length > 0) {
          $('#newAlarm').show();
        }else{
          $('#newAlarm').hide();
        }
        for (var i = 0; i < data.length; i++) {
          var item = data[i];
          var time = moment(item.beginTime).format('YYYY-MM-DD HH:mm:ss');
          // 如果报警类型是 终端报警 则显示 交互 按钮
          // -----------------TODO--------------
          var display='';
          if (item.alarmName == '终端报警') {
            display='inline';
          }else{
            display = 'none';
          }
          var noReadNumber = item.noReadNumber;
          var noReadNumberDisplay='';
          if(noReadNumber>0){
            noReadNumberDisplay='block';
          }else{
            noReadNumberDisplay = 'none';
          }
          var str = `
            <li class="newAlarmList">
                <ul>
                  <li class="newAlarmItem">报警类型：<span class="colorRed">` + item.alarmName + `</span></li>
                  <li class="newAlarmItem">报警地址：` + item.address + `</li>
                  <li class="newAlarmItem">上报时间：` + time + `</li>
                </ul>
                <div class="handleBox">
                  <span class="handleStyle handleBtn btnStyle" index="` + i + `">处理</span>
                  <span class="handleStyle coordinationBtn btnStyle" index="` + i + `">协同</span>
                  <span class="handleStyle endBtn btnStyle">结束</span>
                  <span class="handleStyle talkBtn btnStyle chat-trigger `+display+`" friendid="`+item.devCode+`" alarmid="`+item.alarmId+`">交互<span class="talkTip `+noReadNumberDisplay+`">`+noReadNumber+`</span></span>
                </div>
              </li>`;
          $('#newAlarm .newAlarmListBox ._panel-box').append(str);
        }
      }
    }
  })
}
// 处理和忽略封装ajax内容
function handleIgnoreAjax(alarmId, disposeStatus, devCode, remark, alarmReasons) {

  var ret = getAlarmDisposealarm({
    devCode,
    alarmId,
    remark: remark,
    alarmReasons: alarmReasons,
    disposeStatus
  });
  ret.then(function (data) {
    console.log(data);
    newAlarmFn();
    $("#newAlarmModalBox").removeClass("is-visible3");
  }).catch(function (err) {
    console.log(err);
  });
}

newAlarmFn();
// $.ajax({
//   url: '/alarm/notdispose',
//   success: function (res) {
//     console.log(res);
//     if (res.status == 200) {
//       var data = res.data;
//       newAlarmArr = data;
//       console.log(newAlarmArr.length)
//       $('#newAlarm .newAlarmListBox ._panel-box').html('');
//       if (data.length > 0) {
//         $('#newAlarm').show();
//       }else{
//         $('#newAlarm').hide();
//       }
//       unreadChatNumArr = data;
//       for (var i = 0; i < data.length; i++) {
//         var item = data[i];
//         var time = moment(item.beginTime).format('YYYY-MM-DD HH:mm:ss');
//         // 如果报警类型是 终端报警 则显示 交互 按钮
//         // -----------------TODO--------------
//         var display='';
//         if (item.alarmName == '终端报警') {
//           display='inline';
//         }else{
//           display = 'none';
//         }
//         var noReadNumber = item.noReadNumber;
//         var noReadNumberDisplay='';
//         if(noReadNumber>0){
//           noReadNumberDisplay='block';
//         }else{
//           noReadNumberDisplay = 'none';
//         }
//         var str = `
//           <li class="newAlarmList">
//               <ul>
//                 <li class="newAlarmItem">报警类型：<span class="colorRed">` + item.alarmName + `</span></li>
//                 <li class="newAlarmItem">报警地址：` + item.address + `</li>
//                 <li class="newAlarmItem">上报时间：` + time + `</li>
//               </ul>
//               <div class="handleBox">
//                 <span class="handleStyle handleBtn btnStyle" index="` + i + `">处理</span>
//                 <span class="handleStyle coordinationBtn btnStyle" index="` + i + `">协同</span>
//                 <span class="handleStyle endBtn btnStyle">结束</span>
//                 <span class="handleStyle talkBtn btnStyle chat-trigger `+display+`" friendid="`+item.devCode+`" alarmid="`+item.alarmId+`">交互<span class="talkTip `+noReadNumberDisplay+`">`+noReadNumber+`</span></span>
//               </div>
//             </li>`;
//         $('#newAlarm .newAlarmListBox ._panel-box').append(str);
//       }
//     }
//   }
// })

